package cqrtplm.listener;

import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import com.hustcad.plm.pdm.workflow.annotion.CustomListenerField;
import com.hustcad.plm.pdm.workflow.model.constant.ProcessConstant;
import cqrtplm.service.RTChangeNoticeService;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.impl.el.FixedValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@CustomListener(category = "润通", description = "EBOM发布校验")
public class RTCheckEbomReleaseListener implements ExecutionListener {
    private static final Logger log = LoggerFactory.getLogger(RTCheckEbomReleaseListener.class);


    @Override
    public void notify(DelegateExecution execution) {
        long start = System.currentTimeMillis();
        String workFlowContainerId = execution.getProcessInstanceBusinessKey();
        log.info(
                "----------润通----------EBOM发布校验------workFlowContainerId:{}----->>>",
                workFlowContainerId);
        if (StringUtils.isBlank(workFlowContainerId)) {
            workFlowContainerId = execution.getVariable(ProcessConstant.WORK_FLOW_CONTAINER_ID).toString();
        }

        RTChangeNoticeService rtChangeNoticeService = SpringUtil.getBean(RTChangeNoticeService.class);
        rtChangeNoticeService.checkEbomRelease(workFlowContainerId);
        log.info("----------EBOM发布校验：{}---->>>", System.currentTimeMillis() - start);
    }


}
